package br.com.news.business;

import java.util.Date;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.apache.log4j.Logger;

import br.com.news.business.utils.GenericBusiness;
import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IAuditoriaBusiness;
import br.com.news.utils.database.beans.AuditoriaBean;
import br.com.news.utils.database.beans.UsuarioBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IAuditoriaServiceDb;

@Named
public class AuditoriaBusiness extends GenericBusiness implements IAuditoriaBusiness{

	@Inject
	private IAuditoriaServiceDb auditoriaServiceDb;
	
	@Override
	public List<AuditoriaBean> findAll() throws BusinessException {
		try {
			return auditoriaServiceDb.findAll();
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}

	@Override
	public void save(UsuarioBean usuario, long idObjeto, String tipoObjeto) {
		try {
			AuditoriaBean auditoriaBean = new AuditoriaBean(usuario, new Date(), idObjeto, tipoObjeto);
			auditoriaServiceDb.insert(auditoriaBean);
		} catch (Exception e) {
			Logger.getLogger(AuditoriaBusiness.class).error(e.getMessage(), e);
		}
	}

}
